package com.sort;

import java.util.Random;

public class Test {
    public static void main(String[] args) {
        int[] arr = new int[10000];
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(1000) + 1;
        }
        // int[] arr={41,124,634,23,574,124,734,324,745,2354,745,1234,754,1234,7956,324,685,4312,745,4123,8465,1245};

        long s = System.currentTimeMillis();
        A.quicksort(arr, 0, arr.length - 1);
        long e = System.currentTimeMillis();
        System.out.println(e - s);
    }
}

class A{
    public static void quicksort(int[]arr,int left,int right){
        if(left>=right){
            return;
        }
        int par=partiton(arr,left,right);
        quicksort(arr,left,par-1);
        quicksort(arr,par+1,right);
    }
    public static int partiton(int []arr,int start,int end){
        int pivot=arr[start];
        int i=start;
        while(start<end){
            while (start<end&&arr[end]>=pivot){
                end--;
            }
            while(start<end&&arr[start]<=pivot){
                start++;
            }
            swap(arr,start,end);
        }
        swap(arr,i,start);
        return start;
    }
    public static void swap(int[]arr,int i,int j){
        int tem=arr[i];
        arr[i]=arr[j];
        arr[j]=tem;
    }
}
